
#include <iostream>
#include <mysql/mysql.h>

using namespace std;

int main(int argc, char * argv[]){
    MYSQL conn;
    mysql_init(&conn);
    const char * host = "192.168.10.61";
//    const char * host = "localhost";
    const char * username = "root";
    const char * password = "123";
    const char * db = "test";
    unsigned int port = 3306;
//    const char * table = "test";
//    const char * table = "test";

    if(mysql_real_connect(&conn, host, username, password, db, port, NULL, CLIENT_FOUND_ROWS)){
        int res;
//        res = mysql_query(&conn, "insert into student (name, age, school) values ('张三', 20, '北京大学'), ('李四', 24, '清华大学'), ('王五', 25, '人民大学')");
        res = mysql_query(&conn, "select * from test");
        if(res){
            cout << "error: " << res << endl;
        }else{
            cout << "success: " << res << endl;
            MYSQL_ROW row;
            MYSQL_RES * bk = mysql_store_result(&conn);
            while((row = mysql_fetch_row(bk)) != nullptr){
                std::cout << row[0] << " " << row[1] << std::endl;
//                std::cout << row[0] << " " << row[1] << "  " << row[2] << std::endl;
            }
        }
    }
    mysql_close(&conn);

    return 0;
}
